//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Text;
//using System.Xml;
//using Data;
//using Data.Graph;

//namespace Data.IO
//{
//    /// <summary>
//    /// A class to read files in the GraphML-format. After reading the file, a corresponding graph instance containing all nodes and edges is created. 
//    /// </summary>
//    public class GraphMLReader
//    {

//        #region private members
//        /// <summary>
//        /// The schema keys for nodes
//        /// </summary>
//        private ArrayList nodeschemakeys;

//        /// <summary>
//        /// The schema keys for edges
//        /// </summary>
//        private ArrayList edgeschemakeys;


//        /// <summary>
//        /// The schema for edges
//        /// </summary>
//        private Schema edgeSchema;

//        /// <summary>
//        /// The schema for nodes
//        /// </summary>
//        private Schema nodeSchema;

//        /// <summary>
//        /// The table storing nodes
//        /// </summary>
//        private Table nodeTable;

//        /// <summary>
//        /// The table storing edges
//        /// </summary>
//        private Table edgeTable;

//        /// <summary>
//        /// The graph that is created after reading a GraphML-file
//        /// </summary>
//        private Data.Graph.Graph graph;
//        #endregion

//        #region Setters and getters
//        public Data.Graph.Graph MyGraph
//        {
//            get { return this.graph; }
//        }
//        #endregion

//        #region Constructor
//        public GraphMLReader()
//        {
//            this.graph = null;
//            this.nodeTable = null;
//            this.edgeTable = null;
//        }
//        #endregion

//        #region Public methods
//        /// <summary>
//        /// reads a given GraphML-file
//        /// </summary>
//        /// <param name="filename">The name of the GraphML-file</param>
//        public void readXMLFile(string filename)
//        {
//            XmlTextReader reader = new XmlTextReader(filename);

//            //1. look up graph or key element
//            while (reader.Read())
//            {
//                if (reader.Name == "key")
//                {
//                    this.readGraphMLAttributes(reader);
//                    this.createSchema();
//                    this.createTables();
//                    //break;
//                }

//                else if (reader.Name == "graph")
//                {
//                    this.createGraph(reader);
//                }

//                else if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "node"))
//                {
//                    this.readNodeValues(reader);
//                }

//                else if ((reader.Name == "edge") && (reader.NodeType == XmlNodeType.Element))
//                {
//                    this.readEdgeValues(reader);
//                }
//            }
//        }
//        #endregion

//        #region Private methods
//        /// <summary>
//        /// private helper method used to read a GraphML-file, especially the GraphML-Attributes
//        /// </summary>
//        /// <param name="reader">The current XMLReader instance.</param>
//        private void readGraphMLAttributes(XmlReader reader)
//        {
//            this.nodeschemakeys = new ArrayList();
//            this.edgeschemakeys = new ArrayList();
//            while (reader.Name == "key")
//            {
//                String strId = null, strFor = null, strName = null, strType = null; ;

//                while (reader.MoveToNextAttribute())
//                {
//                    if (reader.Name == "id")
//                        strId = reader.Value;
//                    else if (reader.Name == "for")
//                        strFor = reader.Value;
//                    else if (reader.Name == "attr.name")
//                        strName = reader.Value;
//                    else if (reader.Name == "attr.type")
//                        strType = reader.Value;
//                }

//                SchemaKey aKey = new SchemaKey(strId, strName, strType);
//                if (strFor == "node")
//                    this.nodeschemakeys.Add(aKey);
//                else if (strFor == "edge")
//                    this.edgeschemakeys.Add(aKey);

//                if (reader.ReadToDescendant("default"))
//                {
//                }


//            }
//        }

//        /// <summary>
//        /// private helper method used to read a GraphML-file, creates a schema for nodes and edges respectively
//        /// </summary>
//        private void createSchema()
//        {
//            //this.nodeSchema = new Data.Schema(false);
//            //this.edgeSchema = new Data.Schema(true);
//            if (this.nodeschemakeys.Count > 0)
//            {
//                IEnumerator enumerator = this.nodeschemakeys.GetEnumerator();

//                while (enumerator.MoveNext())
//                {
//                    SchemaKey aKey = (SchemaKey)enumerator.Current;
//                    nodeSchema.AddColumn(aKey.StrAttributeName, aKey.StrAttributeType);

//                }
//            }

//            if (this.edgeschemakeys.Count > 0)
//            {
//                while (this.edgeschemakeys.GetEnumerator().MoveNext())
//                {
//                    SchemaKey aKey = (SchemaKey)this.edgeschemakeys.GetEnumerator().Current;
//                    edgeSchema.addColumn(aKey.StrAttributeName, aKey.StrAttributeType);
//                }
//            }

//        }

//        /// <summary>
//        /// private helper method used to read a GraphML-file, creates the tables for nodes and edges
//        /// </summary>
//        private void createTables()
//        {
//            this.nodeTable = new Data.Table(this.nodeSchema, TargetEntity.Node);
//            this.edgeTable = new Data.Table(this.edgeSchema, TargetEntity.Edge);
//            if (this.graph != null)
//            {
//                //this.graph.addNodeTable(this.nodeTable);
//                //this.graph.addEdgeTable(this.edgeTable);
//            }

//        }

//        /// <summary>
//        /// private helper method used to read a GraphML-file, creates a graph object
//        /// </summary>
//        /// <param name="reader">The current XMLReader instance.</param>
//        private void createGraph(XmlReader reader)
//        {
//            string stredgedefault = null;
//            if (reader.MoveToAttribute("edgedefault"))
//            {
//                stredgedefault = reader.Value;
//                //this.graph = new Data.Graph.Graph(stredgedefault);
//            }
//        }

//        /// <summary>
//        /// private helper method used to read a GraphML-file, especially the node data
//        /// </summary>
//        /// <param name="reader">The current XMLReader instance.</param>
//        private void readNodeValues(XmlReader reader)
//        {
//            Hashtable nodeValues = new Hashtable();
//            while ((reader.Name == "node") && (reader.NodeType == XmlNodeType.Element))
//            {
//                XmlReader subReader = reader.ReadSubtree();
//                // read the ID
//                string tempID = reader.GetAttribute("id");
//                nodeValues.Add("id", tempID);

//                // if a specific schema for nodes exists, read all 'data' element nodes
//                if (this.nodeschemakeys.Count > 0)
//                {
//                    subReader.ReadToDescendant("data");
//                    do
//                    {
//                        string tempKey = subReader.GetAttribute("key");
//                        string tempValue = subReader.ReadString();
//                        nodeValues.Add(tempKey, tempValue);
//                    } while (subReader.ReadToNextSibling("data"));
//                }
//                //this.graph.AddNode(nodeValues);
//            }


//        }

//        /// <summary>
//        /// private helper method used to read a GraphML-file, especially the edge data
//        /// </summary>
//        /// <param name="reader">The current XMLReader instance.</param>
//        /// <returns>The current XMLReader instance.</returns>
//        private void readEdgeValues(XmlReader reader)
//        {
//            Hashtable edgeValues = new Hashtable();
//            // read the values for 'source' and 'target', they are mandatory
//            string tempSource = reader.GetAttribute("source");
//            edgeValues.Add("source", tempSource);
//            string tempTarget = reader.GetAttribute("target");
//            edgeValues.Add("target", tempTarget);

//            // read 'id' and 'directed'
//            string tempID = reader.GetAttribute("id");
//            if (tempID != null)
//                edgeValues.Add("id", tempID);
//            string tempDirected = reader.GetAttribute("directed");
//            if (tempDirected != null)
//                edgeValues.Add("directed", tempDirected);

//            //this.graph.addEdge(edgeValues);

//        }
//        #endregion
//    }
//}